/*Source

Problem Id:2676  User Id:Latex 
Memory:44K  Time:437MS
Language:G++  Result:Accepted

Source 
*/
#include <stdio.h>
#include <string.h>

int flagrow[11][11], flagcol[11][11], flagsub[11][11];
int ans[11][11];
int subnum[11][11];
int exist[11][11];
char ins[100];

inline int getsub(int i, int j)
{
	return (i-1)/3*3+(j+2)/3;
}
bool ok;

void di(int x, int y)
{
	int tox, toy, i ;
	if (ok) return;
	if (x>9)
	{
		ok = true;
		return;
	}
	
	tox= x;
	toy= y+1;
	if (toy>9)
	{
		tox ++;
		toy = 1;
	}
	
	if (exist[x][y])
	{		
		di(tox, toy);
	}
	else
	{
		for (i=1; i<=9; ++i)
			if (flagrow[x][i] ==0 && flagcol[y][i] == 0 && flagsub[ subnum[x][y] ][i] == 0)
			{
				flagrow[x][i] = flagcol[y][i] = flagsub[subnum[x][y]][i] =1;
				ans[x][y] = i;
				di(tox, toy);				
				flagrow[x][i] = flagcol[y][i] = flagsub[subnum[x][y]][i] =0;
				if (ok) return;
			}
	}
}

void check()
{
	int i,j;
	printf("check input:\n");
	for (i=1; i<=9; ++i)
	{
		for (j=1; j<=9; ++j)
			printf("%d ", ans[i][j]);
		printf("\n");
	}
	printf("\n");
	printf("check row:\n");
	for (i=1; i<=9; ++i)
	{
		for (j=1; j<=9; ++j)
			printf("%d ", flagrow[i][j]);
		printf("\n");
	}
	printf("\n");
	printf("check col:\n");
	for (i=1; i<=9; ++i)
	{
		for (j=1; j<=9; ++j)
			printf("%d ", flagcol[i][j]);
		printf("\n");
	}
	printf("\n");
	printf("check sub:\n");
	for (i=1; i<=9; ++i)
	{
		for (j=1; j<=9; ++j)
			printf("%d ", flagsub[i][j]);
		printf("\n");
	}
	printf("\n");
}

int main()
{
	int ncase, i, j;
	
	// init preface
	for (i=1; i<=9; ++i)
		for (j=1; j<=9; ++j)
			subnum[i][j] = getsub(i, j);
	/*
	printf("check pre:\n");
	for (i=1; i<=9; ++i)
	{
		for (j=1; j<=9; ++j)
			printf("%d ", subnum[i][j]);
		printf("\n");
	}
	printf("\n");000000000
	// end of check  */
	
	scanf("%d", &ncase);
	while (ncase--)
	{
		memset(flagrow, 0, sizeof(flagrow));
		memset(flagcol, 0, sizeof(flagcol));
		memset(flagsub, 0, sizeof(flagsub));
		memset(exist, 0, sizeof(exist));
		for (i=1; i<=9; ++i)
		{
			scanf("%s", ins);
			for (j=1; j<=9; ++j)
			{
				ans[i][j] = ins[j-1] - '0';
				if (ans[i][j])
				{
					exist[i][j] = 1;
					flagrow[i][ans[i][j]] = 1;
					flagcol[j][ans[i][j]] = 1;
					flagsub[ subnum[i][j] ][ ans[i][j] ] = 1; 
				}
			}
		}
//		check();
		ok = false;
		di(1,1);
		
		for (i=1; i<=9; ++i)
		{
			for (j=1; j<=9; ++j)
				printf("%d", ans[i][j]);
			printf("\n");
		}
	}
	
	

	return 0;	
}



